package org.rslai.autotest.core.driver;

import java.net.URL;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.remote.DriverCommand;
import org.openqa.selenium.remote.RemoteWebDriver;

public class RemoteWebDriverForAutoTest extends RemoteWebDriver implements TakesScreenshot {

	public RemoteWebDriverForAutoTest(URL remoteAddress, Capabilities desiredCapabilities) {
		super(remoteAddress, desiredCapabilities);
	}

	/**
	 * 实现屏幕截图
	 */
	public <X> X getScreenshotAs(OutputType<X> target) {
		// Get the screenshot as base64.
		String base64 = execute(DriverCommand.SCREENSHOT).getValue().toString();

		// ... and convert it.
		return target.convertFromBase64Png(base64);
	}

}
